#include <stdio.h>
#include <time.h>
#include <pthread.h>    // pthread

#include "debug.h"

#include "logging.h"

void mssleep(unsigned long ms)
{
    struct timespec ts = {
        .tv_sec = (long int) (ms / 1000),
        .tv_nsec = (long int) (ms % 1000) * 1000000ul
    };
    nanosleep(&ts, 0);
}


void ussleep(unsigned long ms)
{
    struct timespec ts = {
        .tv_sec = (long int) (ms / 1000000),
        .tv_nsec = (long int) (ms % 1000000) * 1000ul
    };
    nanosleep(&ts, 0);
}


int test_debug(void)
{
    printf("        test_debug()\n");
    PRINT_ERROR("test error\n" );
    PRINT_WARN("test warn %d\n", 2);
    PRINT_INFO("test info %d\n", 3);
    PRINT_DEBUG("test debug %d\n", 4);

    return 0;
}

#include "test_logging.h"


typedef int (*test_function_p)(void);

test_function_p g_function_arr[] = {
    test_debug,
    test_logging
};



int main()
{
    int i = 0, err_num = 0, succeed_num = 0;

#ifdef VERSION
    printf("\n---------- version: %s ----------\n\n", VERSION);
#endif

    for(i = 0; i < sizeof(g_function_arr)/sizeof(g_function_arr[0]); i++){
        printf("\n===============>");
        if(g_function_arr[i]()) {
            err_num++;
            printf("<===============[failed]\n");
        }
        else {
            succeed_num++;
            printf("<===============[succeed]\n");
        }
	}
    printf("\nsucceed[%d], failed[%d], total[%d]\n", succeed_num, err_num, i);

    return err_num;
}

